﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;

namespace ADDDF.Infrastructure.ChangeTracking.ChangeRecords
{
    class RuleRecord
    {
        private IChangeRule _rule;
        private Dictionary<EntityKey, EntityRecord> _entityRecords;

        public RuleRecord(IChangeRule rule)
        {
            _rule = rule;
            _entityRecords = new Dictionary<EntityKey, EntityRecord>(new EntityKeyEqualityComparer());
        }

        public IChangeRule Rule
        {
            get { return _rule; }
        }

        public void AddEntityRecord(EntityRecord entityRecord)
        {
            EntityKey eKey = new EntityKey { Type = entityRecord.Type, Key = entityRecord.Key };
            if(!_entityRecords.ContainsKey(eKey))
                _entityRecords.Add(eKey, entityRecord);
        }

        public ReadOnlyCollection<EntityRecord> EntityRecords
        {
            get { return new ReadOnlyCollection<EntityRecord>(_entityRecords.Values.ToList()); }
        }
            
    }
}
